home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
LIBRARY
/
PCTV3N3
/
SCROLL.LST
< prev
next >
Wrap
File List
|
1992-06-09
|
5KB
|
189 lines
' SCROLL.FRM
' Demonstration of a scrollable picture viewer.
DefInt A-Z
Const TRUE = -1
Const FALSE = Not TRUE
' Declarations for Windows API functions.
Declare Function StretchBlt% Lib "GDI" (ByVal hDstDC%, ByVal XDst%,
ByVal YDst%, ByVal DstWidth%, ByVal DstHeight%,
ByVal hSrcDC%, ByVal XSrc%, ByVal YSrc%,
ByVal SrcWidth%, ByVal SrcHeight%, ByVal dwRop&)
Declare Function SetStretchBltMode% Lib "GDI"
(ByVal hDC%, ByVal mode%)
Sub Form_Load ()
On Local Error Resume Next
' When the form is loaded, load the desired picture file.
' Insert your own bitmap file or Windows metafile path and
' name.
FileName$ = "d:\windows\my.bmp"
pboxHold.picture = LoadPicture(FileName$)
' Check for errors.
If Err Then
If Err = 53 Then
msg$ = "File " + FileName$ + " not found."
MsgBox (msg$)
End
Else
msg$ = "Error retrieving " + FileName$
MsgBox (msg$)
End
End If
End If
End Sub
Sub Form_Resize ()
On Local Error Resume Next
' This event procedure is executed when the form is first
' displayed and whenever it is resized.
' Insure that the form is 1.6 times as wide as it is high.
Width = 1.6 * Height
' Move the child picture box to the upper
' left corner of the form.
pboxHold.Move 0, 0
' Move the parent picture box to the top left of the
' form. Make it square, large enough to fill the form
' vertically, leaving room for the horizontal scroll bar.
BoxHeight = ScaleHeight - HScroll1.Height
BoxWidth = BoxHeight
pboxView.Move 0, 0, BoxWidth, BoxHeight
' Position the scroll bars at the the bottom and
' right edges of the parent picture box.
HScroll1.left = 0
HScroll1.Top = pboxView.Height
HScroll1.Width = pboxView.Width
VScroll1.Top = 0
VScroll1.left = pboxView.Width
VScroll1.Height = pboxView.Height + HScroll1.Height
' Set the horizontal scroll bar Max property so that full travel
' of the scroll bar represents scrolling across the full width
' of the picture.
HScroll1.Max = pboxHold.Width - pboxView.Width
' Do the same for the vertical scroll bar.
VScroll1.Max = pboxHold.Height - pboxView.Height
' Set the scroll bar change properties so that a large change
' scrolls a distance equal to the width or height of the
' viewing window, and a small change scrolls 1/10th of
' a large change.
HScroll1.LargeChange = HScroll1.Max \
(pboxHold.Width \ pboxView.Width)
HScroll1.SmallChange = HScroll1.LargeChange \ 10
VScroll1.LargeChange = VScroll1.Max \
(pboxHold.Height \ pboxView.Height)
VScroll1.SmallChange = VScroll1.LargeChange \ 10
' Enable the horizontal scroll bar only if the full width
' of the picture is not already showing.
If (pboxView.Width < pboxHold.Width) Then
HScroll1.Enabled = TRUE
Else
HScroll1.Enabled = FALSE
End If
' Enable the vertical scroll bar only if the full height
' of the picture is not already showing.
If (pboxView.Height < pboxHold.Height) Then
VScroll1.Enabled = TRUE
Else
VScroll1.Enabled = FALSE
End If
VScroll1.Refresh
HScroll1.Refresh
' Place pboxImage in the center of the blank area
' on the right side of the form.
BoxWidth = .9 * (ScaleWidth - (pboxView.Width + VScroll1.Width))
BoxHeight = BoxWidth
BoxX = pboxView.Width + VScroll1.Width + BoxWidth * .05
BoxY = (ScaleHeight - BoxHeight) / 2
pboxImage.Move BoxX, BoxY, BoxWidth, BoxHeight
' Copy/compress the image to pboxImage.
XSrc% = 0
YSrc% = 0
XDst% = 0
YDst% = 0
SrcWidth% = pboxHold.ScaleWidth
SrcHeight% = pboxHold.ScaleHeight
DstWidth% = pboxImage.ScaleWidth
DstHeight% = pboxImage.ScaleHeight
' Use StretchBlt copy method to &HCC0020 so that source
' is copied to destination with no special transformations.
dwRop& = &HCC0020
' Set StretchBlt mode to ColorOnColor (2) for best copy of
' a color image.
Result = SetStretchBltMode(pboxImage.hDC, 2)
Result = StretchBlt(pboxImage.hDC, XDst%, YDst%, DstWidth%,
DstHeight%, pboxHold.hDC, XSrc%, YSrc%,
SrcWidth%, SrcHeight%, dwRop&)
pboxImage.picture = pboxImage.Image
On Local Error GoTo 0
End Sub
Sub HScroll1_Change ()
' Move the child picture box to reflect the new position
' of the horizontal scroll bar.
pboxHold.left = -(HScroll1.Value)
End Sub
Sub VScroll1_Change ()
' Move the child picture box to reflect the new position
' of the vertical scroll bar.
pboxHold.Top = -(VScroll1.Value)
End Sub